package com.ruicar.afs.cloud.parameter.commom.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.parameter.commom.condition.ChannelVehicleInfoCondition;
import com.ruicar.afs.cloud.parameter.commom.condition.VehicleCondition;
import com.ruicar.afs.cloud.parameter.commom.condition.VehicleListCondition;
import com.ruicar.afs.cloud.parameter.commom.condition.VehicleTreeCondition;
import com.ruicar.afs.cloud.parameter.commom.entity.TsysVehicleBrand;
import com.ruicar.afs.cloud.parameter.commom.entity.TsysVehicleDetail;
import com.ruicar.afs.cloud.parameter.commom.entity.TsysVehicleModel;
import com.ruicar.afs.cloud.parameter.commom.mapper.TsysVehicleDetailMapper;
import com.ruicar.afs.cloud.parameter.commom.service.TsysVehicleDetailService;
import com.ruicar.afs.cloud.parameter.commom.vo.RuleAtomVO;
import com.ruicar.afs.cloud.parameter.commom.vo.VehicleModelVO;
import com.ruicar.afs.cloud.parameter.commom.vo.VehicleStyleVO;
import com.ruicar.afs.cloud.parameter.commom.vo.VehicleVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 款式明细表
 * @author: sijun.yu
 * @date: 2020/5/15 9:56
 */
@Service
public class TsysVehicleDetailServiceImpl extends ServiceImpl<TsysVehicleDetailMapper, TsysVehicleDetail> implements TsysVehicleDetailService {

    /**
     * 获取品牌信息
     *
     * @param condition
     * @return
     */
    @Override
    public List<TsysVehicleBrand> getVehicleBrandList(VehicleCondition condition) {
        return this.baseMapper.getVehicleBrandList(condition);
    }

    /**
     * 获取车型信息
     *
     * @param condition
     * @return
     */
    @Override
    public List<TsysVehicleModel> getVehicleModelList(VehicleCondition condition) {
        return this.baseMapper.getVehiclemodelList(condition);
    }

    /**
     * 获取款式信息
     *
     * @param condition
     * @return
     */
    @Override
    public List<TsysVehicleDetail> getVehicleStyleList(VehicleCondition condition) {
        return this.baseMapper.getVehicleStyleList(condition);
    }

    /**
     * 通过款式代码和品牌查询款式信息
     * @param code
     * @param modelCode
     * @return
     */
    public TsysVehicleDetail getVehicleDetail(String code,String modelCode){

        TsysVehicleDetail vehicleDetail = this.baseMapper.selectOne(Wrappers.<TsysVehicleDetail>query().lambda()
                .eq(TsysVehicleDetail::getCode,code).eq(TsysVehicleDetail::getModelCode,modelCode));
        return vehicleDetail;
    }

    @Override
    public List<TsysVehicleBrand> getBrandInfo(VehicleTreeCondition condition) {
        return baseMapper.getBrandInfo(condition);
    }


    /**
     * 查询所有的车型数据
     * @param condition
     * @return
     */
    @Override
    public IPage<List<VehicleVO>> getVehicleList(Page page, VehicleListCondition condition) {
        return this.baseMapper.getVehicleList(page,condition);
    }

    /**
     * 品牌树
     * @param condition
     * @return
     */
    @Override
    public List<VehicleTreeCondition> getBrandTree(VehicleTreeCondition condition) {
        return baseMapper.getBrandTree(condition);
    }

    /**
     * 车型树
     * @param condition
     * @return
     */
    @Override
    public List<VehicleTreeCondition> getModelTree(VehicleTreeCondition condition) {
        return baseMapper.getModelTree(condition);
    }

    /**
     * 返回车型列表
     * @param condition
     * @return
     */
    public List getModelList(VehicleCondition condition){

        List<TsysVehicleModel> list = this.getVehicleModelList(condition);
        List<VehicleModelVO> resultList = new ArrayList<VehicleModelVO>();
        for (TsysVehicleModel model : list) {
            VehicleModelVO vo = new VehicleModelVO();
            vo.setBrandId(model.getBrandCode());
            vo.setModelId(model.getCode());
            vo.setModelName(model.getFullName());
            Character firstChar = Character.toUpperCase(model.getSpellCode().charAt(0));
            vo.setFirstChar(firstChar);
            vo.setBrandName(model.getName());
            resultList.add(vo);
        }
        return resultList;
    }


    /**
     * 获取品牌信息【规则使用】
     *
     * @param condition
     * @return
     */
    @Override
    public IPage<List<RuleAtomVO>> getBrandListByRule(Page page,VehicleCondition condition){
        return this.baseMapper.getBrandListByRule(page,condition);
    }

    /**
     * 获取车型信息【规则使用】
     *
     * @param condition
     * @return
     */
    @Override
    public IPage<List<RuleAtomVO>> getModelListByRule(Page page,VehicleCondition condition){
        return this.baseMapper.getModelListByRule(page,condition);
    }

    /**
     * 获取款式信息【规则使用】
     *
     * @param condition
     * @return
     */
    @Override
    public IPage<List<RuleAtomVO>> getStyleListByRule(Page page,VehicleCondition condition){
        return this.baseMapper.getStyleListByRule(page,condition);
    }

    /**
     * 车型树
     * @param condition
     * @return
     */
    @Override
    public ChannelVehicleInfoCondition getVehicleInfoTree(ChannelVehicleInfoCondition condition) {
        return baseMapper.getVehicleInfoTree(condition);
    }

}
